﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{

    /// <summary>
    /// 运行时参数
    /// </summary>
    public class PG1:Group
    {


        /// <summary>
        /// 预测时间选项
        /// =0，运行用户定义的时间范围
        /// =1，运行calmet.dat包含的所有日期
        /// </summary>
        private int m_METRUN = 0;

        public int METRUN
        {
            get { return m_METRUN; }
            set { m_METRUN = value; }
        }

        //起始年月日时分秒

        /// <summary>
        /// 起始年
        /// </summary>
        private int m_IBYR = 2006;

        public int IBYR
        {
            get { return m_IBYR; }
            set { m_IBYR = value; }
        }
        /// <summary>
        /// 起始月
        /// </summary>
        private int m_IBMO = 1;

        public int IBMO
        {
            get { return m_IBMO; }
            set { m_IBMO = value; }
        }
        /// <summary>
        /// 起始日
        /// </summary>
        private int m_IBDY = 1;

        public int IBDY
        {
            get { return m_IBDY; }
            set { m_IBDY = value; }
        }
        /// <summary>
        /// 起始时，00-23
        /// </summary>
        private int m_IBHR = 0;

        public int IBHR
        {
            get { return m_IBHR; }
            set { m_IBHR = value; }
        }
        /// <summary>
        /// 起始分
        /// </summary>
        private int m_IBMIN = 0;

        public int IBMIN
        {
            get { return m_IBMIN; }
            set { m_IBMIN = value; }
        }
        /// <summary>
        /// 起始秒
        /// </summary>
        private int m_IBSEC = 0;

        public int IBSEC
        {
            get { return m_IBSEC; }
            set { m_IBSEC = value; }
        }

        //结束的年月日，时分秒


        /// <summary>
        /// 结束年
        /// </summary>
        private int m_IEYR = 2006;

        public int IEYR
        {
            get { return m_IEYR; }
            set { m_IEYR = value; }
        }
        /// <summary>
        /// 结束月
        /// </summary>
        private int m_IEMO = 12;

        public int IEMO
        {
            get { return m_IEMO; }
            set { m_IEMO = value; }
        }
        /// <summary>
        /// 结束日
        /// </summary>
        private int m_IEDY = 31;

        public int IEDY
        {
            get { return m_IEDY; }
            set { m_IEDY = value; }
        }
        /// <summary>
        /// 结束时
        /// </summary>
        private int m_IEHR = 0;

        public int IEHR
        {
            get { return m_IEHR; }
            set { m_IEHR = value; }
        }
        /// <summary>
        /// 结束分
        /// </summary>
        private int m_IEMIN = 0;

        public int IEMIN
        {
            get { return m_IEMIN; }
            set { m_IEMIN = value; }
        }
        /// <summary>
        /// 结束秒
        /// </summary>
        private int m_IESEC = 0;

        public int IESEC
        {
            get { return m_IESEC; }
            set { m_IESEC = value; }
        }

        //时区，东半球为 负值，西半球为正值，比如UUC+0800，值为-8
        private int m_XBTZ = -8;

        public int XBTZ
        {
            get { return m_XBTZ; }
            set { m_XBTZ = value; }
        }

        /// <summary>
        /// 运行周期，最小为一小时，默认一小时
        /// </summary>
        private int m_NSECDT = 3600;

        public int NSECDT
        {
            get { return m_NSECDT; }
            set { m_NSECDT = value; }
        }

        /// <summary>
        /// 污染物全部种类，包括没有源强的
        /// 因为有化学转化机制存在，预测的污染物不一定都存在污染物的排放
        /// </summary>
        private int m_NSPEC = 1;

        public int NSPEC
        {
            get { return m_NSPEC; }
            set { m_NSPEC = value; }
        }
        /// <summary>
        /// 有排放速率的污染物种类
        /// </summary>
        private int m_NSE = 2;

        public int NSE
        {
            get { return m_NSE; }
            set { m_NSE = value; }
        }


        /// <summary>
        /// 设置后终止运行的标记，1=终止程序，2=设置后继续运行
        /// </summary>
        private int m_ITEST = 2;

        public int ITEST
        {
            get { return m_ITEST; }
            set { m_ITEST = value; }
        }

        /// <summary>
        /// 重启动运行可能把注意力集中到读取和写烟团文件，这也允许将一次运行分隔开
        /// /0=不读或者写一个重启文件
        /// 1=在运行初始，读取一个重启动文件
        /// 2=在运行期间，写入一个重启文件
        /// 3=在运行初始读取一个重启文件并在运行期间写入一个重启文件
        /// </summary>
        private int m_MRESTART = 0;

        public int MRESTART
        {
            get { return m_MRESTART; }
            set { m_MRESTART = value; }
        }

        /// <summary>
        /// 在重启输出循环期间，周期的数量，运行期间写入的重启文件在每个循环结束时更新
        /// =0在最后一个周期写入文件
        /// >0=每个nrespd周期更新文件
        /// </summary>
        private int m_NRESPD = 0;

        public int NRESPD
        {
            get { return m_NRESPD; }
            set { m_NRESPD = value; }
        }
        /// <summary>
        /// 定义使用哪种气象数据格式，和group 0中气象输入文件联用来确定
        /// 1 = (CALMET.DAT) CALMET unformatted file 
        /// 2 = (ISCMET.DAT)  ISC3 ASCII file
        /// 3 = (PLMMET.DAT) AUSPLUME ASCII file
        /// 4 = CTDMPLUS tower file (PROFILE.DAT) and surface parameters file (SURFACE.DAT
        /// </summary>
        private int m_METFM = 1;

        public int METFM
        {
            get { return m_METFM; }
            set { m_METFM = value; }
        }


        /// <summary>
        /// 确定剖面文件PROFILE.DAT数据类型
        /// = 1， CTDM plus tower file (PROFILE.DAT)
        /// = 2， AERMET tower file (PROFILE.DAT)
        /// </summary>
        private int m_MPRFFM = 1;

        public int MPRFFM
        {
            get { return m_MPRFFM; }
            set { m_MPRFFM = value; }
        }

        /// <summary>
        /// 平均时间，单位：分mPG
        /// </summary>
        private double m_AVET = 60;

        public double AVET
        {
            get { return m_AVET; }
            set { m_AVET = value; }
        }
        /// <summary>
        /// PG稳定度 平均时间
        /// </summary>

        private double m_PGTIME = 60;

        public double PGTIME
        {
            get { return m_PGTIME; }
            set { m_PGTIME = value; }
        }






        //private int m_fCount;
        //private bool m_fEndTime;
        //private bool m_fRunLength;
        //private int m_fTHD;

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {

                if (m_dic.Key == "METRUN")
                {
                    this.METRUN = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBYR")
                {
                    this.IBYR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBMO")
                {
                    this.IBMO = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBDY")
                {
                    this.IBDY = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "IBHR")
                {
                    this.IBHR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBMIN")
                {
                    this.IBMIN = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IBSEC")
                {
                    this.IBSEC = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEYR")
                {
                    this.IEYR = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "IEMO")
                {
                    this.IEMO = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEDY")
                {
                    this.IEDY = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEHR")
                {
                    this.IEHR = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "IEMIN")
                {
                    this.IEMIN = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "IESEC")
                {
                    this.IESEC = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "XBTZ")
                {
                    this.XBTZ = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NSECDT")
                {
                    this.NSECDT = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NSPEC")
                {
                    this.NSPEC = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "NSE")
                {
                    this.NSE = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "ITEST")
                {
                    this.ITEST = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MRESTART")
                {
                    this.MRESTART = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "NRESPD")
                {
                    this.NRESPD = Convert.ToInt32(m_dic.Value);
                }

                if (m_dic.Key == "METFM")
                {
                    this.METFM = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "MPRFFM")
                {
                    this.MPRFFM = Convert.ToInt32(m_dic.Value);
                }
                if (m_dic.Key == "AVET")
                {
                    this.AVET = Convert.ToDouble(m_dic.Value);
                }
                if (m_dic.Key == "PGTIME")
                {
                    this.PGTIME = Convert.ToDouble(m_dic.Value);
                }
            }
        }
        public override string WriteToGroup()
        {
            string ResultStr = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 1 -- General run control parameters" + "\r\n";
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            TempStr = "! METRUN = " + METRUN.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBYR = " + IBYR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBMO = " + IBMO.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBDY = " + IBDY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBHR = " + IBHR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBMIN = " + IBMIN.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IBSEC = " + IBSEC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEYR = " + IEYR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEMO = " + IEMO.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEDY = " + IEDY.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEHR = " + IEHR.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IEMIN = " + IEMIN.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            TempStr = "! IESEC = " + IESEC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! XBTZ = " + XBTZ.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! NSECDT = " + NSECDT.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! NSPEC = " + NSPEC.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! NSE = " + NSE.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! ITEST = " + ITEST.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! MRESTART = " + MRESTART.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! NRESPD = " + NRESPD.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! METFM = " + METFM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! MPRFFM = " + MPRFFM.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! AVET = " + AVET.ToString() + " !" + "\r\n";
            ResultStr += TempStr;


            TempStr = "! PGTIME = " + PGTIME.ToString() + " !" + "\r\n";
            ResultStr += TempStr;

            ResultStr += "!END!" + "\r\n";

            return ResultStr;
        }


    }
}
